﻿@{
    ViewBag.Title = "Home Page";
}
<body id="wrapper">
    <p id="pageTitle" align="center">Bot Detector</p>
    <div align="center">
        <input type="text" id="question" class="inputt" /><br /><br />
        <div align="left" id="checkBoxes">
            <input id="bing" type="checkbox" checked="true">Bing<br />
            <input id="google" type="checkbox">Google<br /><br />
        </div>
        <input type="button" value="Search" id="searchButton" />

        <p id="subtitle">History</p> <br />


        <table id="results">
            <tr id="orange">
                <td class="column">Phrase</td>
                <td class="column">BingResult</td>
                <td class="column">GoogleResult</td>
                <td class="column">BingGoogleResult</td>
            </tr>
        </table>
    </div>
</body>
@section scripts{
    <script type="text/javascript">
        $('#searchButton').click(function () {
            var searchEngine = "";
            if (document.getElementById('bing').checked && document.getElementById('google').checked) {
                searchEngine = "Both";
            }
            else
                if (document.getElementById('bing').checked) {
                    searchEngine = "Bing";

                }
                else
                    if (document.getElementById('google').checked) {
                        searchEngine = "Google";

                    }

            $.getJSON('/api/request/q=' + document.getElementById("question").value + '/searchEngine=' + searchEngine, function (contactsJsonPayload) {
                $(contactsJsonPayload).each(function (i, item) {
                    if (searchEngine == "Bing") {
                        if (item.IsBot == "true") {
                            $('#results').append('<tr id="red"><td class="column">' + document.getElementById("question").value + '</td><td class="column">' + "Is Bot" + '</td><td class="column"></td><td class="column"></td></tr>');
                        }
                        else {
                            $('#results').append('<tr id="green"><td class="column">' + document.getElementById("question").value + '</td><td class="column">' + "Not Bot" + '</td><td class="column"></td><td class="column"></td></tr>');
                        }
                    }
                    else
                        if (searchEngine == "Google") {
                            if (item.IsBot == "true") {
                                $('#results').append('<tr id="red"><td class="column">' + document.getElementById("question").value + '</td><td class="column"></td><td class="column">' + "Is Bot" + '</td><td class="column"></td></tr>');
                            }
                            else {
                                $('#results').append('<tr id="green"><td class="column">' + document.getElementById("question").value + '</td><td class="column"></td><td class="column">' + "Not Bot" + '</td><td class="column"></td></tr>');
                            }
                        }
                        else
                            if (searchEngine == "Both") {
                                if (item.IsBot == "true") {
                                    $('#results').append('<tr id="red"><td class="column">' + document.getElementById("question").value + '</td><td class="column"></td><td class="column"></td><td class="column">' + "Is Bot" + '</td></tr>');
                                }
                                else {
                                    $('#results').append('<tr id="green"><td class="column">' + document.getElementById("question").value + '</td><td class="column"></td><td class="column"></td><td class="column">' + "Not Bot" + '</td></tr>');
                                }
                            }

                });
            });
        });
    </script>
}
